// ---------------------------------------------------------------------------------------------------------------------
// COUNTERS.h
// ---------------------------------------------------------------------------------------------------------------------
// Project:	Alpha Branch Predictor
// Authors:	Jabeer Ahmed, 
// 			Omar Mohsin, 
// 			Fadi Butti
// Course:	ECE - 586 (Winter 2013)
// Prof:	Mark Faust
// Portland State University
// ---------------------------------------------------------------------------------------------------------------------

#ifndef __COUNTERS_H__
#define __COUNTERS_H__

#include <iostream>
#include <string>
#include "types.h"

using namespace std;
struct counter2
{
	uint bits:2;
	counter2()			:bits(1)	{};
	counter2(int val)	:bits(val){};
	counter2(char val)	:bits(val){};
	counter2(short val)	:bits(val){};
	counter2(uint val)	:bits(val){};

	counter2& operator++(int){if(bits<3)this->bits++; return *this;}
	counter2& operator--(int){if(bits>0)this->bits--; return *this;}
	bool   isTaken()	{ return bits & 0x2;}
	string isTakenStr()	{ return (isTaken()) ? string("taken"):string("not taken");}
    friend ostream& operator<<(ostream& lhs, const counter2& rhs)
    {
        return lhs << rhs.bits; 
    }
};

struct counter3
{
	uint bits:3;
	counter3()			:bits(3)  {};
	counter3(int val)	:bits(val){};
	counter3(char val)	:bits(val){};
	counter3(short val)	:bits(val){};
	counter3(uint val)	:bits(val){};
	bool   isTaken()	{ return bits & 0x4;}
	string isTakenStr()	{ return (isTaken()) ? string("taken"):string("not taken");}
	counter3& operator++(int){if(bits<7)this->bits++; return *this;}
	counter3& operator--(int){if(bits>0)this->bits--; return *this;}
    friend ostream& operator<<(ostream& lhs, const counter3& rhs)
    {
        return lhs << rhs.bits; 
    }
};

#endif 	// __COUNTERS_H__